#!/bin/bash

rm -rf /root/mongdb/mongodb-linux-x86_64-4.1.3/config/logs
mkdir -p /root/mongdb/mongodb-linux-x86_64-4.1.3/config/logs
# 启动配置节点1
rm -rf /root/mongdb/mongodb-linux-x86_64-4.1.3/config/config1
rm /root/mongdb/mongodb-linux-x86_64-4.1.3/config/logs/config1.log
mkdir -p /root/mongdb/mongodb-linux-x86_64-4.1.3/config/config1
touch /root/mongdb/mongodb-linux-x86_64-4.1.3/config/logs/config1.log
/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/config/config-17017.conf
# 启动配置节点2
rm -rf /root/mongdb/mongodb-linux-x86_64-4.1.3/config/config2
rm /root/mongdb/mongodb-linux-x86_64-4.1.3/config/logs/config2.log
mkdir -p /root/mongdb/mongodb-linux-x86_64-4.1.3/config/config2
touch /root/mongdb/mongodb-linux-x86_64-4.1.3/config/logs/config2.log
/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/config/config-17018.conf
# 启动配置节点3
rm -rf /root/mongdb/mongodb-linux-x86_64-4.1.3/config/config3
rm /root/mongdb/mongodb-linux-x86_64-4.1.3/config/logs/config3.log
mkdir -p /root/mongdb/mongodb-linux-x86_64-4.1.3/config/config3
touch /root/mongdb/mongodb-linux-x86_64-4.1.3/config/logs/config3.log
/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/config/config-17019.conf

sleep 60

# 节点集群配置
# 注意use admin
/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongo localhost:17017/admin /root/mongdb/mongodb-linux-x86_64-4.1.3/config/initialize_configsvr.js

# 启动配置分片1 节点1
rm -rf /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37017
rm /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37017.log
mkdir -p /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37017
touch /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37017.log
/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37017.conf
# 启动配置分片1 节点2
rm -rf /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37018
rm /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37018.log
mkdir -p /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37018
touch /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37018.log
/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37018.conf
# 启动配置分片1 节点3
rm -rf /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37019
rm /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37019.log
mkdir -p /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37019
touch /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37019.log
/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37019.conf

sleep 60

# 分片集群1配置 37017
/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongo localhost:37017 /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/initialize_shard1.js

# 启动配置分片2 节点1
rm -rf /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47017
rm /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47017.log
mkdir -p /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47017
touch /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47017.log
/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47017.conf
# 启动配置分片2 节点2
rm -rf /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47018
rm /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47018.log
mkdir -p /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47018
touch /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47018.log
/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47018.conf
# 启动配置分片2 节点3
rm -rf /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47019
rm /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47019.log
mkdir -p /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47019
touch /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47019.log
/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47019.conf

sleep 60

# 分片集群2配置 47017
/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongo localhost:47017 /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/initialize_shard2.js

# 启动路由节点
rm -rf /root/mongdb/mongodb-linux-x86_64-4.1.3/route/logs/
mkdir -p /root/mongdb/mongodb-linux-x86_64-4.1.3/route/logs/
rm /root/mongdb/mongodb-linux-x86_64-4.1.3/route/logs/route.log
touch /root/mongdb/mongodb-linux-x86_64-4.1.3/route/logs/route.log
/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongos -f /root/mongdb/mongodb-linux-x86_64-4.1.3/route/route-27017.conf

sleep 60

# 路由节点配置
/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongo localhost:27017 /root/mongdb/mongodb-linux-x86_64-4.1.3/route/initialize_route.js